#include <iostream>
using namespace std;
bool judge(int n)
{
    long long tmp = n * n;
    int c = n;
    int a = 0;
    while (n)
    {
        int num = tmp % 10;
        a = a * 10 + num;
        n /= 10;
        tmp /= 10;
    }
    int b = 0;
    while (a)
    {
        b = b * 10 + a % 10;
        a /= 10;
    }
    if (b == c)
    {
        return true;
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; ++i)
    {
        if (judge(i))
        {
            ++sum;
        }
    }
    cout << sum << endl;
    return 0;
}